const mongoose = require("mongoose");


mongoose.connect('mongodb://39.97.227.68:27017/mall', {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  useFindAndModify: true,
  useCreateIndex: true,
});

var db = mongoose.connection
db.on('error', function () {
  console.log('数据库连接失败');
});
db.on('open', function () {
  console.log('数据库连接成功');
});
db.on('disconnected', function () {
  console.log('数据库连接断开');
});

// 构建user的model
var userSchem = mongoose.Schema({
  "id": Number,
  "uid": String,
  "username": String,
  "userImg": String,
  "sex": Number,
  "birthDate": String,
  "password": String,
  "name": String,
  "reg_time": String,
  "introduction": String,
  "tel": String
})
// 构建classify的model   (商品分类)
var classifySchema = mongoose.Schema({
  classify_id: String,
  classify_name: String
})

//构建good 的model（商品）
var goodSchem = mongoose.Schema({
  "id":Number,
	"pcate":Number,//一级分类id
	"ccate":Number,//二级分类id
	"tcate":Number,//三级分类id
	"type":Number,//商品类型
	"status":Number,// 商品状态 0下架 1上架
	"shopid":Number,//店铺id
	"commentid":Number,//评价id
	"label":Array,//标签
	"waiter":Array,//提供服务
	"skuid":Number,//skuid
	"title":String,//商品名称
	"imgs":Array, //banner
	"details":Array//详情
})

exports.Classify = mongoose.model('classifys', classifySchema)
exports.Good = mongoose.model('good', goodSchem)